<?php
namespace app\admin\controller;
use think\Db;
class Index extends Base{
    public function index(){
    	$admininfo=Db::name('admin')->where('username',session('username'))->find();
        session('admininfo', $admininfo);
        if($admininfo['role_id']!=0){
        	$adminrules=Db::name('adminrole')->where('id',$admininfo['role_id'])->find();
    		$this->assign('adminrulearr',explode(',', $adminrules['one']));
    		// $this->assign('adminrulearrs',explode(',', $adminrules['two']));
        }
    	$this->assign('username',session('username'));
        return $this->fetch();
    }
    //清除缓存
    public function cacheFile(){
        //定义目录绝对路劲
        define('JGLJ',str_replace('application/admin/controller','',str_replace('\\','/',__DIR__)));
        $dir =  JGLJ .'runtime/cache';
        
        if($this->deldir($dir)){
               $this->success('清除成功！');
        }else{
            $this->error('清除失败！');
        }
    }
    //清除日志
    public function logFile(){
        //定义目录绝对路劲
        define('JGLJ',str_replace('application/admin/controller','',str_replace('\\','/',__DIR__)));
        $dir =  JGLJ .'runtime/log';
        
        if($this->deldir($dir)){
               $this->success('清除成功！');
        }else{
            $this->error('清除失败！');
        }
    }
    //清除临时文件
    public function tempFile(){
        //定义目录绝对路劲
        define('JGLJ',str_replace('application/admin/controller','',str_replace('\\','/',__DIR__)));
        $dir =  JGLJ .'runtime/temp';
        
        if($this->deldir($dir)){
               $this->success('清除成功！');
        }else{
            $this->error('清除失败！');
        }
    }
    private function deldir($dir) {
        //先删除目录下的文件：
        $dh=opendir($dir);
        while ($file=readdir($dh)) {
            if($file!="." && $file!="..") {
                $fullpath=$dir."/".$file;
                if(!is_dir($fullpath)) {
                    unlink($fullpath);
                } else {
                    $this->deldir($fullpath);
                }
            }
        }
        closedir($dh);
        //删除当前文件夹：
        if(rmdir($dir)) {
            return true;
        } else {
            return false;
        }
    }
}
